/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-10-17
*/
package com.rzico.market.service;

import com.rzico.base.BaseMapper;
import com.rzico.base.impl.BaseServiceImpl;
import com.rzico.market.entity.MarketOrderApplyItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.rzico.market.mapper.MarketOrderApplyItemMapper;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

/**
 * <pre>
 * 京东订单商品信息业务类
 * </pre>
 *
 * @author Rzico Boot
 * @version 1.0
 */
@Service
public class MarketOrderApplyItemService extends BaseServiceImpl<MarketOrderApplyItem, String> {

    @Autowired
    private MarketOrderApplyItemMapper marketOrderApplyItemMapper;

    @Override
    public BaseMapper<MarketOrderApplyItem, String> getMapper() {
        return marketOrderApplyItemMapper;
    }

    /**
     * 保存京东订单商品信息
     * @param map
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public MarketOrderApplyItem saveMarketOrderApplyItem(Map<String, Object> map){
        MarketOrderApplyItem marketOrderApplyItem = new MarketOrderApplyItem();
        marketOrderApplyItem.setCreateDate(new Date());
        marketOrderApplyItem.setOrderApplyId((Long) map.get("order_apply_id"));
        marketOrderApplyItem.setCost((BigDecimal) map.get("cost"));
        marketOrderApplyItem.setName(map.get("name").toString());
        marketOrderApplyItem.setPrice((BigDecimal) map.get("price"));
        marketOrderApplyItem.setQuantity((BigDecimal) map.get("quantity"));
        marketOrderApplyItem.setSn(map.get("sn").toString());
        marketOrderApplyItem.setSpec(map.get("spec").toString());
        marketOrderApplyItem.setUnit(map.get("unit").toString());
        marketOrderApplyItem.setThumbnail(map.get("thumbnail").toString());
        marketOrderApplyItem.setProductId((Long) map.get("product_id"));
        marketOrderApplyItem.setEnterpriseId((Long) map.get("enterprise_id"));
        marketOrderApplyItemMapper.insertUseGeneratedKeys(marketOrderApplyItem);
        MarketOrderApplyItem result = super.findById(marketOrderApplyItem.getId());
        return result;
    }

}
